﻿using System;
using System.Data;

using System.Collections.Generic;
using System.Text;
using WinnerCMS.Common;
using WinnerCMS.Model;
using System.Linq;

namespace WinnerCMS.Data 
{
    /// <summary>
    /// 采集栏目下5页的url缓存
    /// </summary>
    public class GatherUrlCacheDal 
    {
        /// <summary>
        /// 缓存这些URL
        /// </summary>
        /// <param name="models"></param>
        public void Cache(GatherUrlCache[] models)
        {
            using (Entities db = new Entities())
            {
                foreach (var v in models)
                {
                    db.GatherUrlCaches.Add(v);
                }
                db.SaveChangesAsync().Wait();
            }
        }
       /// <summary>
       /// 读取缓存的url地址
       /// </summary>
       /// <param name="pUrlMd5"></param>
       /// <returns></returns>
        public string[] ReadNextPages(string pUrlMd5)
        {
            using (Entities db = new Entities())
            {
                var v = from x in db.GatherUrlCaches
                        where x.PUrlMD5 == pUrlMd5
                        select x.NextPageUrl;
                return v.ToArray();
            } 
        }
    }
}